package com.sx.zongzhi.adapter;


import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;

import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.ContactBean;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.List;

/**
 * Created by XZY on 2017/11/23.
 * 群组 层级联系人的adapter
 */
public class ContactAdapter extends CommonAdapter<ContactBean> {

    private Context context;

    public ContactAdapter(Context context, int layoutId, List<ContactBean> datas) {
        super(context, layoutId, datas);
        this.context=context;
    }

    @Override
    protected void convert(ViewHolder viewHolder, final ContactBean item, int position) {
        viewHolder.setText(R.id.checkbox,item.getName());
        if (item.getPhone()!=null){
            viewHolder.setText(R.id.tv_Phone,item.getPhone());
        }
        final ImageView imageView = viewHolder.getView(R.id.iv_img);
        if (item.isSelect()){
            imageView.setImageResource(R.mipmap.img_selected);
        }else {
            imageView.setImageResource(R.mipmap.img_default);
        }
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.isSelect()){
                    item.setSelect(false);
                    imageView.setImageResource(R.mipmap.img_default);
                }else {
                    item.setSelect(true);
                    imageView.setImageResource(R.mipmap.img_selected);
                }
            }
        });
//        CheckBox checkBox = viewHolder.getView(R.id.checkbox);
//        checkBox.setChecked(item.isSelect());
//        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//                item.setSelect(isChecked);
//            }
//        });
    }
}
